package com.atguigu.srb.core.controller.admin;

import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.entity.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.entity.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * ClassName: AdminBorrowerController
 * Package: com.atguigu.srb.core.controller.admin
 * Description:
 *
 * @Author 王晓龙
 * @Create 2023/4/7 10:05
 * @Version 1.0
 */
@Api("借款人管理")
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource
    BorrowerService borrowerService;

    @ApiOperation("条件分页查询借款人列表")
    @GetMapping("/{pageNum}/{pageSize}")
    public Result list(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            String key
    ){
        Page<Borrower> page = new Page<>(pageNum, pageSize);
        borrowerService.getListByKey(page, key);
        return Result.ok().data("page", page);
    }

    @ApiOperation("根据借款人id查询借款人详情")
    @GetMapping("/{id}")
    public Result getById(
            @PathVariable Long id
    ){
        BorrowerVO borrowerVo = borrowerService.getBorrowerById(String.valueOf(id));
        return Result.ok().data("vo", borrowerVo);
    }

    @ApiOperation("审批")
    @PostMapping("/approval")
    public Result approval(
            @RequestBody BorrowerApprovalVO vo){
        borrowerService.approval(vo);
        return Result.ok();
    }
}
